<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h2>获取当前时间</h2>
		<div id="gdiv1">
			
		</div>
		<button type="button" onclick="get1()">GET1</button>
		<h2>随机一句名言</h2>
		<div id="gdiv2">
			
		</div>
		<button type="button" onclick="get2()">GET2</button>
		<h2>获取诗词作者列表(GET)</h2>
		<div id="gdiv3">
			
		</div>
		<button type="button" onclick="get3()">GET3</button>
		<h2>获取诗词列表(GET)</h2>
		<div id="gdiv4">
			
		</div>
		<button type="button" onclick="get4()">GET4</button>
		<h2>获取诗词列表-包含作者信息(GET)</h2>
		<div id="gdiv5">
			
		</div>
		<button type="button" onclick="get5()">GET5</button>
		<h2>获取网易新闻</h2>
		<div id="pdiv1">
			
		</div>
		<button type="button" onclick="post1()">POST1</button>
		<h2>用户反馈</h2>
		<div id="pdiv2">
			
		</div>
		<button type="button" onclick="post2()">POST2</button>
		<h2>用户登陆</h2>
		<div id="pdiv3">
			
		</div>
		<button type="button" onclick="post3()">POST3</button>
		<h2>用户登陆</h2>
		<div id="pdiv3">
			
		</div>
		<button type="button" onclick="post3()">POST3</button>
		<h2>删除反馈</h2>
		<div id="pdiv4">
			
		</div>
		<button type="button" onclick="post4()">POST4</button>
		<h2>获取宋朝古诗词</h2>
		<div id="pdiv5">
			
		</div>
		<button type="button" onclick="post5()">POST5</button>
	</body>
	<script type="text/javascript">
		function get1(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/getTime') ;
			ajax.send() ;
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText) ;
					var p = obj.result.date + '<br />' + obj.result.time + '<br />' + obj.result.weekday ;
					document.getElementById('gdiv1').innerHTML = p ;
				}
			}
		}
		function get2(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/sentences');
			ajax.send() ;
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText) ;
					var p = '来源：' + obj.result.from + '<br />' + '诗句：' + obj.result.name ;
					document.getElementById('gdiv2').innerHTML = p ;
				}
			}
		}
		function get3(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=杜甫') ;
			ajax.send() ;
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText) ;
					var p = '姓名：' + obj.result.name + '<br />' + '简介：' + obj.result.simpleIntro ;
					document.getElementById('gdiv3').innerHTML = p ;
				}
			}
		}
		function get4(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetry?count=2&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText) ;
					var p = '诗名：' + obj.result[0].title + '<br />' + '朝代：' + obj.result[0].dynasty + '<br />' + '诗人：' + obj.result[0].writer + '<br />' + '内容：' + obj.result[0].content ;
					document.getElementById('gdiv4').innerHTML = p ;
				}
			}
		}
		function get5(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryFull?count=2&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					var p = '诗人：' + obj.result[0].writer + '<br />' + '简介：' + obj.result[0].simpleIntro + '<br />' + '诗名：' + obj.result[0].title + '<br />' + '朝代：' + obj.result[0].dynasty + '<br />' + '内容：' + obj.result[0].content ;
					document.getElementById('gdiv5').innerHTML = p ;
				}
			}
		}
		function post1(){
			var ajax = new XMLHttpRequest();
			var a = 1 ;
			var b = 5 ;
			ajax.open('POST','https://api.apiopen.top/getWangYiNews');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			ajax.send(a,b);
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					var p = '' ;
					for(var i=0 ; i<b ; i++){
						p += '标题：' + obj.result[a].title + '<br />' + '时间：' + obj.result[a].passtime + '<br />' ;
						a++ ;
					}
					document.getElementById('pdiv1').innerHTML = p ;
				}
			}
		}
		function post2(){
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/userFeedback');
			ajax.send('9648872f9aa08da137ce45fe1dda8279','我觉得应该再增加个版本更新功能。','135@qq.com');
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					console.log(obj.result);
				}
			}
		}
		function post3(){
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/loginUser');
			ajax.send('d0058f79caae5300dcba65f128e52855','peakchao','123456');
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					var p = '昵称：' + obj.result.nikeName + '<br />' + '手机号：' + obj.result.phone + '<br />' + '邮箱：' + obj.result.email ;
					document.getElementById('pdiv3').innerHTML = p ;
				}
			}
		}
		function post4(){
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/deleteFeedback');
			ajax.send('9648872f9aa08da137ce45fe1dda8279',1);
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					console.log(obj.result);
				}
			}
		}
		function post5(){
			var ajax = new XMLHttpRequest();
			var a = 1 ;
			var b = 3 ;
			ajax.open('POST','https://api.apiopen.top/getSongPoetry');
			ajax.send(a,b);
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					var obj = JSON.parse(ajax.responseText);
					console.log(obj.result);
					var p = '' ;
					for(var i=0 ; i<b ; i++){
						p += '诗/词名：' + obj.result.title + '<br />' + '作者：' + obj.result[a].authors + '<br />' + '主体：' + obj.result[a].content + '<br />' ;
						a++;
					}
					document.getElementById('pdiv5').innerHTML = p ;
				}
			}
		}
	</script>
</html>
